package org.embedchat.database;

public class DatabaseProvider {

	public static DatabaseProvider ourInstance
		= new DatabaseProvider();
	public static final String DEFAULT_IMPLEMENTATION
		= "org.embedchat.database.nodb.DAOFactory";
	public DAOFactoryInterface factory;
	
	private DatabaseProvider() {
		//TODO: add properties
		// Try to define factory from properties
		// If no success, use default factory
		try {
			Class clazz = Class.forName(DEFAULT_IMPLEMENTATION);
			this.factory = (DAOFactoryInterface) clazz.newInstance();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static DatabaseProvider getInstance() {
		return ourInstance;
	}
	
	public DAOFactoryInterface getDAOFactory() {
		return factory;
	}
}
